﻿#region Creditos

/* Autor: Edilberto Sánchez Forero	*/
/* Email: esanchezfo@gmail.com		*/
/* Licencia: LGPL, Software Libre	*/
/* País: Colombia, Bogotá			*/

#endregion

#region Librerias

using System;
using System.Collections.Generic;
using System.Linq;

#endregion


namespace ESF.MSExcel.Structures
{
	[Serializable]
	public class XlsBCRelations
	{
		#region Miembros
		
		public List<XlsBCItem> Sources;		
		public List<XlsBCItem> Targets;
		
		public List<XlsBCItem> SourceTags;
		public List<XlsBCItem> TargetTags;
		
		#endregion
		
		
		#region Funciones
		
		public void GetTargetsAndTags (XlsBCItem pSource, out List<KeyValuePair<XlsBCItem, XlsCell>> pTargets, out List<KeyValuePair<XlsBCItem, XlsCell>> pTags)
		{	
			pTargets = GetTargets (pSource);
				
			pTags = GetTags (pSource);
		}
		
		
		public List<KeyValuePair<XlsBCItem, XlsCell>> GetTags (XlsBCItem pSource)
		{	
			return (from SrTg in pSource.TagRelations
				join Tg in SourceTags on SrTg.ColIndex equals Tg.ContentCell.ColIndex
				select new KeyValuePair <XlsBCItem, XlsCell> (Tg, SrTg)).ToList <KeyValuePair<XlsBCItem, XlsCell>>();
		}
		
		
		public List<KeyValuePair<XlsBCItem, XlsCell>> GetTargets (XlsBCItem pSource)
		{	
			return (from SrT in pSource.Relations
				join T in Targets on SrT.ColIndex equals T.ContentCell.ColIndex
				select new KeyValuePair <XlsBCItem, XlsCell> (T, SrT)).ToList <KeyValuePair <XlsBCItem, XlsCell>> ();
		}
		
		
		public void GetTags (XlsBCItem pTarget, out List<KeyValuePair<XlsBCItem, XlsCell>> pTargetTags)
		{
			pTargetTags = (from TrTg in pTarget.TagRelations
				join Tg in TargetTags on TrTg.ColIndex equals Tg.ContentCell.ColIndex
				select new KeyValuePair <XlsBCItem, XlsCell> (Tg, TrTg)).ToList <KeyValuePair<XlsBCItem, XlsCell>>();
		}
		
		#endregion
	}
}